//
//  HLTextField.swift
//  HLSwiftWork
//
//  Created by hulinhu on 2018/6/16.
//  Copyright © 2018年 hulinhu. All rights reserved.
//

import UIKit

fileprivate let kPlaceholerLabelKey = "_placeholderLabel.textColor"
fileprivate let leftMargin = 5

// 重写 UITextField
// 设置文本左间距

class HLTextField: UITextField {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        tintColor = UIColor.white
        font = UIFont.systemFont(ofSize: 16)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func becomeFirstResponder() -> Bool {
        
        self.setValue(textColor, forKeyPath: kPlaceholerLabelKey)
        return super.becomeFirstResponder()
    }
    override func resignFirstResponder() -> Bool {
        self.setValue(UIColor.gray, forKeyPath: kPlaceholerLabelKey)
        return super.resignFirstResponder()
    }
    
    override func textRect(forBounds bounds: CGRect) -> CGRect {
        return CGRect(x: bounds.origin.x + 10, y: bounds.origin.y, width: bounds.size.width - 10, height: bounds.size.height)
    }
    
    override func editingRect(forBounds bounds: CGRect) -> CGRect {
        return CGRect(x: bounds.origin.x + 10, y: bounds.origin.y, width: bounds.size.width - 10, height: bounds.size.height)
    }



}
